package dennis;

import java.util.ArrayList;
import java.util.Scanner;

public class CommandInput {
	
	//public static String buffer;
	public static boolean Importance = false;
	static String command;
	static ArrayList<String> output = new ArrayList<String>();
	
	public static void main(String[] args) {
		// Reads a single line from the console 
		// and stores into name variable
		
		// uncomment the below three lines to take in commands.
		//Scanner in = new Scanner(System.in);
		//command = in.nextLine(); //nextline for strings 
		//in.close();            
		
		//comment away the line below to take in from keyboard
		command = "+ * l:sports jogging with David @ 7pm # 120312 $ Park";
		
		CommandInput newInput = new CommandInput(command);
		newInput.parseCmd();
		//newInput.out2console();
		
	}
	/*start of modification, may 27 - defeng, also replaced all System.out.println() with output.add()
	 * 
	 */
	
	//constructor
	public CommandInput(String ainput){
		command = ainput;
	}
	
	public static void parseCmd(){
		String[] temp;
		//delimiter
				String delimiter = " ";
				//given string will be split by the argument delimiter provided.
				temp = command.split(delimiter);
				
				if(temp[0].equals("+") || temp[0].equals("+*"))
					AddTask(temp);
				else if(temp[0].equals("-"))
					//RemoveTask(temp);
					;
				else if(temp[0].equals("mod"))
					//ModifyTask(temp);
					;
				else if(temp[0].equals("view"))
					//ViewTask(temp);
					;
				else if(temp[0].equals("search"))
					//SearchTask(temp);
					;
				else if(temp[0].equals("done"))
					//DoneTask(temp);
					;
				else
					output.add("Command error!");
				
				output.add("Complete."); //this is for testing
	}
	
    //pass Object with statements to be displayed to GUI
    public static ArrayList<String> out(){
    	return output;
    	
    }
    
    //print to console instead
    public static void out2console(){
    	int size = output.size();
        
		 for(int i = 0; i < size ; i++){
			 //output.add(size);
			 String astr = output.get(i);
			 System.out.println(astr);
		 }
		 output.clear();
    }
    
	
	/*end of modification - defeng, may 27
	 */
	
	public static void AddTask(String[] item) {
		
		int i=0,j=0;
		char[] temp;
		String TaskDescription="";
		
		if(item[0].equals("+*")) {
			Importance = true;
			if(Importance)
				output.add("Importance Stored.");
		}
		
		while(!(item[i].equals("@") || item[i].equals("#") || item[i].equals("#"))) {
			if(!(item[i].equals("+") || item[i].equals("*") || item[i].equals("+*"))){
				TaskDescription = TaskDescription + item[i]+" ";
			}
			i++;
		}StoreTaskDescription(TaskDescription); //store the task description
		
		for(i =0; i < item.length ; i++) {
			
			//create an object
			//store these
			if(item[i].equals("@")) {
				StoreTime(item[i+1]);
				output.add("Time Stored.");
			}
			else if(item[i].equals("#")) {
				StoreDate(item[i+1]);
				output.add("Date Stored.");
			}
			else if(item[i].equals("*")) {
				Importance = true;
				if(Importance)
					output.add("Importance Stored.");
			}
			else if(item[i].equals("$")) {
				StoreVenue(item[i+1]);
				output.add("Venue Stored.");
			}
		}
	}
	
	
	public static void StoreTaskDescription(String task) {
		output.add(task+" sentence");
		
		String[] checkforlabel;
		String storetask="";
		
		char[] labelcheck;
		String label="";
		
		//given string will be split by the argument delimiter provided.
		checkforlabel = task.split(" ");
		int lengthoftask = checkforlabel.length-1;
		
		labelcheck = checkforlabel[0].toCharArray();
		if(labelcheck[0]=='l' && labelcheck[1]==':') {
			for (int i=1; i<=lengthoftask; i++) {
				storetask = storetask+checkforlabel[i]+" ";
			}
			for (int i=2; i<=labelcheck.length-1; i++) {
				label=label+labelcheck[i];
			}
		}
		else 
			storetask = task;
		
		output.add(storetask+" task");
		output.add(label+" label");
		// call for Store task description here
		// call for Store label description here
	}
	public static void StoreTime(String time) {
		output.add(time+" <time"); //this is for testing
		// call for Store time here
	}
	public static void StoreVenue(String venue) {
		output.add(venue+" <venue");
		// call for Store venue here
	}
	public static void StoreDate(String date) {
		output.add(date+" <date");
		int dd,mm,yy;
		char[] ddmmyy;
		
		ddmmyy = date.toCharArray();
		dd = ((ddmmyy[0]-48)*10) + (ddmmyy[1]-48);
		output.add(dd+" <dd");
		// call for Store dd here
		mm = ((ddmmyy[2]-48)*10) + (ddmmyy[3]-48);
		output.add(mm+" <mm");
		// call for Store mm here
		yy = ((ddmmyy[4]-48)*10) + (ddmmyy[5]-48);
		output.add(yy+" <yy");
		// call for Store yy here
	}
}